#!/bin/sh

#
# Test writing a resource to an offset
#

. "$(cd "$(dirname "$0")" && pwd)/common.sh"

cat >$CONFIG <<EOF
file-resource subdir/TEST {
        host-path = "${TESTFILE_150K}"
}

task complete {
	on-resource subdir/TEST { raw_write(1) }
}
EOF

# Create the firmware file, then "burn it"
$FWUP_CREATE -c -f $CONFIG -o $FWFILE
$FWUP_APPLY -a -d $IMGFILE -i $FWFILE -t complete

# The firmware file is equivalent to the following dd call
# (The conv=sync makes sure that the output is a multiple of 512 bytes)
dd if=$TESTFILE_150K seek=1 of=$WORK/check.bin conv=sync 2>/dev/null
cmp_bytes 51712 $WORK/check.bin $IMGFILE

# Check that the verify logic works on this file
$FWUP_VERIFY -V -i $FWFILE
